// 2025/07/29
// Author: Forever
#include <bits/stdc++.h>
using namespace std;

int n, m;
__uint128_t ans, dp[81][81], p[81];

template <typename T>
T read(){
    T x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

void write(__uint128_t x)
{
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

__uint128_t solve(){
    for (int i = 1; i <= m; i++)
        p[i] = read<__uint128_t>();
    for (int len = m - 1; len >= 1; len--)
        for (int i = 1; i + len - 1 <= m; i++){
            dp[i][i + len - 1] = 0;
            if (i > 1)
                dp[i][i + len - 1] = max(dp[i][i + len - 1], dp[i - 1][i + len - 1] + (p[i - 1] << (m - len)));
            if (i + len <= m)
                dp[i][i + len - 1] = max(dp[i][i + len - 1], dp[i][i + len] + (p[i + len] << (m - len)));
        }
    __uint128_t res = 0;
    for (int i = 1; i <= m; i++)
        res = max(res, dp[i][i] + (p[i] << m));
    return res;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    n = read<int>(), m = read<int>();
    for (int i = 1; i <= n; i++)
        ans += solve();
    write(ans);
    return 0;
}